package dpss.commons;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * User input helper class
 * @author musab.mirza
 *
 */
public class UserInput {
	
	/**
	 * Reads line from console and returns it
	 * 
	 * @return
	 */
	public static String readLine() {
		System.out.print("==> ");
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String read = null;
		try {
			read = br.readLine();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return read;
	}

	/**
	 * Reads an integer from console and returns it
	 * 
	 * @return
	 * @throws Exception
	 */
	public static int readInt() throws Exception {
		System.out.print("==> ");
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try {
			try {
				int i = Integer.parseInt(br.readLine());
				return i;
			} catch (NumberFormatException nfe) {
				throw new Exception("Invalid number");
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
		return 0;
	}

}
